<template>
    <div class="container">
        <div class="userinfo">
            <img src="../../../static/images/icn.png" alt="">
            <p>王小二的书柜</p>
        </div>
        <div class="text">您暂未授权王小二的书柜小程序获取你的信息，将无法正常使用小程序的功能。如需要正常使用，请点击“授权”按钮，打开头像，昵称等信息的授权</div>
        <button class="btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="onGotUserInfo">授权登录</button>
        <button class="btn" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="handleGetPhoneNumber">获取手机号码</button>
    </div>
</template>

<script>
import qcloud from 'wafer2-client-sdk'
import { get,showSuccess } from '@/utils'
import config from '@/config'
export default {
    methods: {
        onGotUserInfo (e) { // 获取用户信息
            qcloud.setLoginUrl(config.loginUrl);
            qcloud.login({
                success: function (userInfo) {
                    console.log('登录成功', userInfo);
                    showSuccess('登录成功')
                    wx.setStorage({
                        key: 'userInfo',
                        data: userInfo
                    })
                    wx.switchTab({
                        url: '/pages/me/main',
                        
                    })
                },
                fail: function (err) {
                    console.log('登录失败', err);
                }
            });
        },
        handleGetPhoneNumber (e) { // 获取手机号码
            console.log(e)
        }
    },
}
</script>

<style>
.text {
    color: #cccccc;
    font-size: 14px;
    margin: 100rpx 0;
    text-align: center;
    width: 100%;
}
</style>
